package wcm;

import java.awt.Color;
import robocode.Robot;
import robocode.ScannedRobotEvent;
import robocode.HitWallEvent;
import robocode.HitRobotEvent;
import robocode.util.Utils;

/**
 * This robot bounces around the walls of the battlefield and changes it's course
 * slightly during its run in order to keep enemies unbalanced.
 * @author wing ma
 *
 */
public class Bato extends Robot {
  //Amount of turns for Bato
  Double turnAmount;
  
  /**
   *This method moves the robot in a small circle and turns the gun to scan for targets.
   */
  public void run() {
    
    //set robot colors
    setBodyColor(Color.black);
    setGunColor(Color.gray);
    setRadarColor(Color.red);
    setBulletColor(Color.white);
    setScanColor(Color.white);

    turnAmount = 50.0;
    turnGunLeft(90); 
    
    while (true) {
      turnLeft(30);
      ahead(1000);
      
    }
  }  
  
  /**
   *When a robot has been found by radar, fire.
   *@param ro - is the enemy robot
   */
  public void onScannedRobot(ScannedRobotEvent ro) {
    
    fire(3);
  }
  
  /**
   *When this robot hits a wall, it will turn and move away.
   *@param ro is the enemy robot
   */
  public void onHitWall(HitWallEvent ro) {

    turnLeft(turnAmount);
    ahead(100);
  }
  
  /**
   *When a collision occurs between two robots, check if it's our fault and ram again
   *if it is. This strategy for ramming is copied from Kendyll Doi's GunAryos.
   *TurnAmount will also be changed in order to prevent future collisions.
   *@param ro is enemy robot
   */
  public void onHitRobot(HitRobotEvent ro) {
    
    Double fightAngle = Utils.normalRelativeAngleDegrees(ro.getBearing());
    turnRight(fightAngle);
    Boolean collideFault = ro.isMyFault();
    
    turnAmount = 80.0;
    
    if (collideFault) {
      ahead(10);
      turnRight(180);
      ahead(150);
    }
    
    
    scan();
  }
  
}
